package com.breeze.blockchain.controller.admin.form.permission;

import static com.breeze.blockchain.mybatis.entity.table.PermissionTable.PERMISSION;

import com.breeze.blockchain.mybatis.entity.PermissionDo;
import com.breeze.components.mybatis.page.AbstractPageQuery;
import com.mybatisflex.core.query.If;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 权限列表
 *
 * @author breeze
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema
public class PermissionPageForm extends AbstractPageQuery<PermissionDo> {

  @Schema(title = "权限ids")
  List<Long> ids;

  @Schema(title = "权限名称")
  String name;

  @Schema(title = "是否禁用: 0:启用 1:禁用")
  Integer disabled;

  @Schema(title = "权限key")
  String key;

  @Override
  public QueryWrapper toQueryWrapper() {
    return super.toQueryWrapper()
        .where(
            PERMISSION
                .ID
                .in(getIds(), If::isNotEmpty)
                .and(PERMISSION.NAME.like(getName(), If::hasText))
                .and(PERMISSION.KEY.like(getKey(), If::hasText))
                .and(PERMISSION.DISABLED.eq(getDisabled(), If::notNull)))
        .orderBy(PERMISSION.SORT.desc())
        .orderBy(PERMISSION.ID.desc());
  }
}
